package com.mt.course.service.model;

import java.util.List;
import java.util.Map;

import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import com.github.pagehelper.PageHelper;
import com.mt.common.PagerInfo;
import com.mt.common.ServiceResult;
import com.mt.course.entity.ZhiboEntity;
import com.mt.course.mapper.ZhiboEntityMapper;

@Component
public class ZhiboServiceModel {
    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(ZhiboServiceModel.class);

    @Autowired
    private ZhiboEntityMapper zhiboEntityMapper;

    public ServiceResult<List<ZhiboEntity>> selectList(Map<String, Object> params, PagerInfo<?> pagerInfo) {
        Assert.notNull(this.zhiboEntityMapper, "Property 'zhiboEntityMapper' is required.");
        ServiceResult<List<ZhiboEntity>> result = new ServiceResult<List<ZhiboEntity>>();
        try {
            if (pagerInfo != null) {
                PageHelper.startPage(pagerInfo.getPageIndex(), pagerInfo.getPageSize());
            }

            result.setResult(this.zhiboEntityMapper.selectList(params));
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ZhiboServiceModel][selectList]：query selectList occur exception", e);
        }
        return result;
    }

    public ServiceResult<ZhiboEntity> selectInfo(Map<String, Object> params) {
        Assert.notNull(this.zhiboEntityMapper, "Property 'zhiboEntityMapper' is required.");
        ServiceResult<ZhiboEntity> result = new ServiceResult<ZhiboEntity>();
        try {
            result.setResult(this.zhiboEntityMapper.selectByPrimaryKey(params));
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ZhiboServiceModel][selectInfo]：query selectInfo occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> insert(ZhiboEntity zhiboEntity) {
        Assert.notNull(this.zhiboEntityMapper, "Property 'zhiboEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int id = 0;
        try {
            int save = this.zhiboEntityMapper.insert(zhiboEntity);
            if (save > 0) {
                id = zhiboEntity.getZhiboId();
            }
            result.setResult(id);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ZhiboServiceModel][insert]：query insert occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> updateRelate(ZhiboEntity zhiboEntity) {
        Assert.notNull(this.zhiboEntityMapper, "Property 'zhiboEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int id = 0;
        try {
            int save = this.zhiboEntityMapper.updateByPrimaryKeySelective(zhiboEntity);
            if (save > 0) {
                id = zhiboEntity.getZhiboId();
            }
            result.setResult(id);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ZhiboServiceModel][updateByPrimaryKeySelective]:query update occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> updateByPrimaryKeySelective(ZhiboEntity zhiboEntity) {
        Assert.notNull(this.zhiboEntityMapper, "Property 'zhiboEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int id = 0;
        try {
            int save = this.zhiboEntityMapper.updateByPrimaryKeySelective(zhiboEntity);
            if (save > 0) {
                id = zhiboEntity.getZhiboId();
            }
            result.setResult(id);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ZhiboServiceModel][updateByPrimaryKeySelective]:query update occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> deleteByPrimaryKey(Integer zhiboId) {
        Assert.notNull(this.zhiboEntityMapper, "Property 'zhiboEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int save = 0;
        try {
            save = this.zhiboEntityMapper.deleteByPrimaryKey(zhiboId);
            result.setResult(save);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ZhiboServiceModel][updateByPrimaryKeySelective]:query update occur exception", e);
        }
        return result;
    }
}
